<?php

namespace app\crontab;

//心愿任务

use app\model\UserWish;
use think\Exception;
use think\facade\Db;

class Wish
{


    /**
     * 心愿刷新
     */
    public function refresh()
    {
        Db::startTrans();
        try {
            $time = date('Y-m-d H:i:s', (time()-WISH_REFRESH_TIME));

            $user_wish_list = (new UserWish())::where('updated_at','<=',$time)->where('status', WISH_STATUS['刷新中'])->select();
            foreach ($user_wish_list as $user_wish) {
                $user_wish->status = WISH_STATUS['已更新'];
                $user_wish->save();
            }
            Db::commit();
            //var_dump('心愿完成');

        } catch (Exception $e) {
            var_dump('执行异常' . $e->getMessage());
        }
    }



}